﻿using Bystd.Geo.Geometries;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bystd.Geo.GeoParsers.GeoPackage
{
    public class GeometryReader : BaseBytes
    {
        public GeoType GeometryType { get; private set; }
        public int SRID { get; private set; }

        public GeometryReader(byte[] buffer, int offset = 0)
            : base(buffer, offset)
        {

        }

        public Geometry Reader()
        {
            var header = GeoPackageHeader.Read(Buffer, Offset);
            Wkb.GeometryReader reader = new Wkb.GeometryReader(Buffer, Offset + header.HeaderLength + 1, header.byteOrder);
            var geo = reader.Reader();

            geo.Ordinates = header.Ordinates;
            geo.SRID = header.SRID;
            SRID = header.SRID;
            GeometryType = geo.GeometryType;
            return geo;
        }
    }
}
